﻿/*----------------------------------------------------------------
           // Copyright (C) 2008 安华顺通(北京)科技有限公司
           // 版权所有。 
           //
           // 文件名：MenuItemsContextMenu.cs
           // 文件功能描述：目录项的右键菜单。
           //
           // 
           // 创建标识：杨波20080925
           //
           // 修改标识：
           // 修改描述：
           //
           // 修改标识：
           // 修改描述：
//----------------------------------------------------------------*/

#region UsingStatements

using System;
using System.Data;

#endregion

namespace RuleCode.ObjectTree
{
    public partial class MenuItemsContextMenu : SychronizeContextMenu
    {
        public MenuItemsContextMenu()
        {
            InitializeComponent();
        }

        protected override void sycToolStripMenuItem_Click(object sender, EventArgs e)
        {
            base.sycToolStripMenuItem_Click(sender, e);
            //删除已有数据
            SqlHelper.Instance.ExecuteNonQuery(CommandType.Text, "Delete  from MenuItem");
            foreach (SysTreeNode node in Util.SelectedNode.Nodes)
            {
                node.ExpandAll();
                foreach (SysTreeNode subNode in node.Nodes)
                {
                    int type = 0;
                    subNode.ExpandAll();
                    if (node.Text == "显示")
                    {
                        type = 0;

                    }
                    if (node.Text == "输出")
                    {
                        type = 1;
                    }
                    if (node.Text == "动作")
                    {
                        type = 2;
                    }
                    Util.SetPropertyContent(subNode);
                    //SqlHelper.Instance.ExecuteNonQuery(CommandType.Text,
                    //                                   "INSERT INTO  [dbo].[目录项] ([DATAAREAID] ,[RECID],[目录项编码],[目录项类型],[名称]" +
                    //                                   ",[对象类型],[对象名称]" +
                    //                                   " ,[标签编码],[模块名称]) VALUES('" + "" + "', "
                    //                                   + Convert.ToString(Util.GetNewRecId)
                    //                                   +
                    //                                   ", '" +
                    //                                   subNode.Property.ID + "' ," + type + " ,'" + subNode.Text +
                    //                                   "' ," + 0 + " ,'" +
                    //                                   ((MenuItemProperty)subNode.Property).Object + "' ,'" +
                    //                                   ((MenuItemProperty)subNode.Property).Label + "' ,'" + ((MenuItemProperty)subNode.Property).SubPath +
                    //                                   "')");
                    SqlHelper.Instance.ExecuteNonQuery(CommandType.Text,
                                                      "INSERT INTO  [dbo].[MenuItem] ([DATAAREAID] ,[RECID],[MenuItemID],[MenuItemType],[Name]" +
                                                      ",[ObjectType],[ObjectName]" +
                                                      " ,[Label],[ModlueName]) VALUES('" + "" + "', "
                                                      + Convert.ToString(Util.GetNewRecId)
                                                      +
                                                      ", '" +
                                                      subNode.Property.ID + "' ," + type + " ,'" + subNode.Text +
                                                      "' ," + 0 + " ,'" +
                                                      ((MenuItemProperty)subNode.Property).Object + "' ,'" +
                                                      ((MenuItemProperty)subNode.Property).Label + "' ,'" + ((MenuItemProperty)subNode.Property).SubPath +
                                                      "')");
                }
            }
        }
    }


}